<template>
    <div class="newsflash">
        <section class="newsheader">
            <div class="headercon">
                <h2>{{$t('gonggao[0]')}}</h2>
                <h3>{{$t('gonggao[1]')}}</h3>
            </div>
        </section>
        <section class="newscont">
            <el-tabs :value="tabstype" tab-position="left"  @tab-click="tabclick">
                <el-tab-pane :label="$t('gonggao[2]')" name="1">
                    <ul class="gonggao">
                        <li class="list" v-for="(item, index) in informationdata.data" :key="index">
                            <h3 class="h3">
                                <div v-html="item.title"></div>
                            </h3>
                            <h4 class="h4">
                                <router-link :to="{name:'newsflashdetails',query:{id: item.posts_id}}">{{$t('gonggao[3]')}}></router-link>
                                <p>{{item.created_at}}</p>
                            </h4>
                        </li>
                    </ul>
                    <PagesSize :content="informationdata" @func="getMsgFormSon"></PagesSize>
                </el-tab-pane>
                <el-tab-pane :label="$t('gonggao[4]')" name="2">
                    <ul class="gonggao">
                        <li class="list" v-for="(item, index) in announcementdata.data" :key="index">
                            <h3 class="h3">
                                <div v-html="item.title"></div>
                            </h3>
                            <h4 class="h4">
                                <router-link :to="{name:'systemannouncementdetails',query:{id: item.posts_id}}">{{$t('gonggao[3]')}}></router-link>
                                <p>{{item.updated_at}}</p>
                            </h4>
                        </li>
                    </ul>
                    <PagesSize :content="announcementdata" @func="getMsgFormSon"></PagesSize>
                </el-tab-pane>
            </el-tabs>
        </section>
    </div>
</template>

<script>
import { systemPosts, news } from '@/api/software';
import PagesSize from "_dom/paging"
export default {
    name: "newsflash",
    data() {
        return {
            informationdata:[],
            announcementdata:[],
            changedata:{
               page: "1",
            },
            tabstype: "1",
        };
    },
    methods: {
        information(data){
            let _data = {
                type: data,
            };
            _data.page = this.changedata.page;
            news(_data).then(res => {
                if(res.data.status_code == 200){
                    this.informationdata = res.data.data;
                }
            }).catch(err => {
                this.$message.error(err.msg);
            });
        },
        getMsgFormSon(datavue){
            this.changedata = datavue;
            switch (this.tabstype) {
                case "1":
                    this.information("2");
                    break;
                case "2":
                    this.announcement("3");
                    break;
                default:
                    break;
            }
        },
        tabclick(row){
            this.changedata = {
                page: "1",
            };
            switch (row.name) {
                case "1":
                    this.information("2");
                    break;
                case "2":
                    this.announcement("1");
                    break;
                default:
                    break;
            };
        },
        announcement(data){
            let _data = {
                type: data,
            };
            _data.page = this.changedata.page;
            systemPosts(_data).then(res => {
                if(res.data.status_code == 200){
                    this.announcementdata = res.data.data;
                }else{
                    
                }
            }).catch(err => {
                this.$message.error(err.msg);
            });
        }
    },
    created(){
        this.information("2");
        this.announcement("1");
    },
    components: {
         PagesSize,
    },
};
</script>

